<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>class HTML::Selector - Rails Framework Documentation</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="../Object.html">Object</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-c-for_class">::for_class</a>
    
    <li><a href="#method-c-for_id">::for_id</a>
    
    <li><a href="#method-c-new">::new</a>
    
    <li><a href="#method-i-attribute_match">#attribute_match</a>
    
    <li><a href="#method-i-match">#match</a>
    
    <li><a href="#method-i-next_element">#next_element</a>
    
    <li><a href="#method-i-next_selector">#next_selector</a>
    
    <li><a href="#method-i-nth_child">#nth_child</a>
    
    <li><a href="#method-i-only_child">#only_child</a>
    
    <li><a href="#method-i-select">#select</a>
    
    <li><a href="#method-i-select_first">#select_first</a>
    
    <li><a href="#method-i-simple_selector">#simple_selector</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/actionmailer-3_2_7/MIT-LICENSE.html">MIT-LICENSE</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/actionmailer-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/actionpack-3_2_7/MIT-LICENSE.html">MIT-LICENSE</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/actionpack-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/activemodel-3_2_7/MIT-LICENSE.html">MIT-LICENSE</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/activemodel-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/activerecord-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/activeresource-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/activesupport-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="..//usr/local/lib/ruby/gems/1_9_1/gems/railties-3_2_7/README_rdoc.html">README</a>
  
    <li class="file"><a href="../README_rdoc.html">README</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../ActiveRecord.html">ActiveRecord</a>
  
    <li><a href="../ActiveRecord/ActiveRecordError.html">ActiveRecord::ActiveRecordError</a>
  
    <li><a href="../ActiveRecord/AdapterNotFound.html">ActiveRecord::AdapterNotFound</a>
  
    <li><a href="../ActiveRecord/AdapterNotSpecified.html">ActiveRecord::AdapterNotSpecified</a>
  
    <li><a href="../ActiveRecord/Aggregations.html">ActiveRecord::Aggregations</a>
  
    <li><a href="../ActiveRecord/Aggregations/ClassMethods.html">ActiveRecord::Aggregations::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AssociationTypeMismatch.html">ActiveRecord::AssociationTypeMismatch</a>
  
    <li><a href="../ActiveRecord/Associations.html">ActiveRecord::Associations</a>
  
    <li><a href="../ActiveRecord/Associations/ClassMethods.html">ActiveRecord::Associations::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeAssignment.html">ActiveRecord::AttributeAssignment</a>
  
    <li><a href="../ActiveRecord/AttributeAssignment/ClassMethods.html">ActiveRecord::AttributeAssignment::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeAssignmentError.html">ActiveRecord::AttributeAssignmentError</a>
  
    <li><a href="../ActiveRecord/AttributeMethods.html">ActiveRecord::AttributeMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/BeforeTypeCast.html">ActiveRecord::AttributeMethods::BeforeTypeCast</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/ClassMethods.html">ActiveRecord::AttributeMethods::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/DeprecatedUnderscoreRead.html">ActiveRecord::AttributeMethods::DeprecatedUnderscoreRead</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/DeprecatedUnderscoreRead/ClassMethods.html">ActiveRecord::AttributeMethods::DeprecatedUnderscoreRead::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Dirty.html">ActiveRecord::AttributeMethods::Dirty</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/PrimaryKey.html">ActiveRecord::AttributeMethods::PrimaryKey</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/PrimaryKey/ClassMethods.html">ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Query.html">ActiveRecord::AttributeMethods::Query</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Read.html">ActiveRecord::AttributeMethods::Read</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Read/ClassMethods.html">ActiveRecord::AttributeMethods::Read::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Serialization.html">ActiveRecord::AttributeMethods::Serialization</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Serialization/Attribute.html">ActiveRecord::AttributeMethods::Serialization::Attribute</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Serialization/ClassMethods.html">ActiveRecord::AttributeMethods::Serialization::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/TimeZoneConversion.html">ActiveRecord::AttributeMethods::TimeZoneConversion</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/TimeZoneConversion/ClassMethods.html">ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Write.html">ActiveRecord::AttributeMethods::Write</a>
  
    <li><a href="../ActiveRecord/AttributeMethods/Write/ClassMethods.html">ActiveRecord::AttributeMethods::Write::ClassMethods</a>
  
    <li><a href="../ActiveRecord/AutosaveAssociation.html">ActiveRecord::AutosaveAssociation</a>
  
    <li><a href="../ActiveRecord/AutosaveAssociation/ClassMethods.html">ActiveRecord::AutosaveAssociation::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Base.html">ActiveRecord::Base</a>
  
    <li><a href="../ActiveRecord/Batches.html">ActiveRecord::Batches</a>
  
    <li><a href="../ActiveRecord/Calculations.html">ActiveRecord::Calculations</a>
  
    <li><a href="../ActiveRecord/Callbacks.html">ActiveRecord::Callbacks</a>
  
    <li><a href="../ActiveRecord/ConfigurationError.html">ActiveRecord::ConfigurationError</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/AbstractAdapter.html">ActiveRecord::ConnectionAdapters::AbstractAdapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/AbstractMysqlAdapter.html">ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/ConnectionHandler.html">ActiveRecord::ConnectionAdapters::ConnectionHandler</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/ConnectionManagement.html">ActiveRecord::ConnectionAdapters::ConnectionManagement</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/ConnectionPool.html">ActiveRecord::ConnectionAdapters::ConnectionPool</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/DatabaseLimits.html">ActiveRecord::ConnectionAdapters::DatabaseLimits</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/DatabaseStatements.html">ActiveRecord::ConnectionAdapters::DatabaseStatements</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/Mysql2Adapter.html">ActiveRecord::ConnectionAdapters::Mysql2Adapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/MysqlAdapter.html">ActiveRecord::ConnectionAdapters::MysqlAdapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/MysqlAdapter/StatementPool.html">ActiveRecord::ConnectionAdapters::MysqlAdapter::StatementPool</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/StatementPool.html">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::StatementPool</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/TableDefinition.html">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/Utils.html">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Utils</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/PostgreSQLColumn.html">ActiveRecord::ConnectionAdapters::PostgreSQLColumn</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/QueryCache.html">ActiveRecord::ConnectionAdapters::QueryCache</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/Quoting.html">ActiveRecord::ConnectionAdapters::Quoting</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SQLiteAdapter.html">ActiveRecord::ConnectionAdapters::SQLiteAdapter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SQLiteAdapter/ExplainPrettyPrinter.html">ActiveRecord::ConnectionAdapters::SQLiteAdapter::ExplainPrettyPrinter</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SQLiteAdapter/StatementPool.html">ActiveRecord::ConnectionAdapters::SQLiteAdapter::StatementPool</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SQLiteAdapter/Version.html">ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SchemaCache.html">ActiveRecord::ConnectionAdapters::SchemaCache</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/SchemaStatements.html">ActiveRecord::ConnectionAdapters::SchemaStatements</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/StatementPool.html">ActiveRecord::ConnectionAdapters::StatementPool</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/Table.html">ActiveRecord::ConnectionAdapters::Table</a>
  
    <li><a href="../ActiveRecord/ConnectionAdapters/TableDefinition.html">ActiveRecord::ConnectionAdapters::TableDefinition</a>
  
    <li><a href="../ActiveRecord/ConnectionNotEstablished.html">ActiveRecord::ConnectionNotEstablished</a>
  
    <li><a href="../ActiveRecord/ConnectionTimeoutError.html">ActiveRecord::ConnectionTimeoutError</a>
  
    <li><a href="../ActiveRecord/CounterCache.html">ActiveRecord::CounterCache</a>
  
    <li><a href="../ActiveRecord/DangerousAttributeError.html">ActiveRecord::DangerousAttributeError</a>
  
    <li><a href="../ActiveRecord/Delegation.html">ActiveRecord::Delegation</a>
  
    <li><a href="../ActiveRecord/DynamicFinderMatch.html">ActiveRecord::DynamicFinderMatch</a>
  
    <li><a href="../ActiveRecord/DynamicMatchers.html">ActiveRecord::DynamicMatchers</a>
  
    <li><a href="../ActiveRecord/DynamicScopeMatch.html">ActiveRecord::DynamicScopeMatch</a>
  
    <li><a href="../ActiveRecord/Explain.html">ActiveRecord::Explain</a>
  
    <li><a href="../ActiveRecord/FinderMethods.html">ActiveRecord::FinderMethods</a>
  
    <li><a href="../ActiveRecord/Fixtures.html">ActiveRecord::Fixtures</a>
  
    <li><a href="../ActiveRecord/Fixtures/File.html">ActiveRecord::Fixtures::File</a>
  
    <li><a href="../ActiveRecord/IdentityMap.html">ActiveRecord::IdentityMap</a>
  
    <li><a href="../ActiveRecord/IdentityMap/Middleware.html">ActiveRecord::IdentityMap::Middleware</a>
  
    <li><a href="../ActiveRecord/Inheritance.html">ActiveRecord::Inheritance</a>
  
    <li><a href="../ActiveRecord/Inheritance/ClassMethods.html">ActiveRecord::Inheritance::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Integration.html">ActiveRecord::Integration</a>
  
    <li><a href="../ActiveRecord/InvalidForeignKey.html">ActiveRecord::InvalidForeignKey</a>
  
    <li><a href="../ActiveRecord/IrreversibleMigration.html">ActiveRecord::IrreversibleMigration</a>
  
    <li><a href="../ActiveRecord/Locking.html">ActiveRecord::Locking</a>
  
    <li><a href="../ActiveRecord/Locking/Optimistic.html">ActiveRecord::Locking::Optimistic</a>
  
    <li><a href="../ActiveRecord/Locking/Optimistic/ClassMethods.html">ActiveRecord::Locking::Optimistic::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Locking/Pessimistic.html">ActiveRecord::Locking::Pessimistic</a>
  
    <li><a href="../ActiveRecord/LogSubscriber.html">ActiveRecord::LogSubscriber</a>
  
    <li><a href="../ActiveRecord/Migration.html">ActiveRecord::Migration</a>
  
    <li><a href="../ActiveRecord/Migration/CommandRecorder.html">ActiveRecord::Migration::CommandRecorder</a>
  
    <li><a href="../ActiveRecord/MigrationProxy.html">ActiveRecord::MigrationProxy</a>
  
    <li><a href="../ActiveRecord/ModelSchema.html">ActiveRecord::ModelSchema</a>
  
    <li><a href="../ActiveRecord/ModelSchema/ClassMethods.html">ActiveRecord::ModelSchema::ClassMethods</a>
  
    <li><a href="../ActiveRecord/MultiparameterAssignmentErrors.html">ActiveRecord::MultiparameterAssignmentErrors</a>
  
    <li><a href="../ActiveRecord/NestedAttributes.html">ActiveRecord::NestedAttributes</a>
  
    <li><a href="../ActiveRecord/NestedAttributes/ClassMethods.html">ActiveRecord::NestedAttributes::ClassMethods</a>
  
    <li><a href="../ActiveRecord/NestedAttributes/TooManyRecords.html">ActiveRecord::NestedAttributes::TooManyRecords</a>
  
    <li><a href="../ActiveRecord/Observer.html">ActiveRecord::Observer</a>
  
    <li><a href="../ActiveRecord/Persistence.html">ActiveRecord::Persistence</a>
  
    <li><a href="../ActiveRecord/Persistence/ClassMethods.html">ActiveRecord::Persistence::ClassMethods</a>
  
    <li><a href="../ActiveRecord/PreparedStatementInvalid.html">ActiveRecord::PreparedStatementInvalid</a>
  
    <li><a href="../ActiveRecord/QueryCache.html">ActiveRecord::QueryCache</a>
  
    <li><a href="../ActiveRecord/QueryCache/ClassMethods.html">ActiveRecord::QueryCache::ClassMethods</a>
  
    <li><a href="../ActiveRecord/QueryMethods.html">ActiveRecord::QueryMethods</a>
  
    <li><a href="../ActiveRecord/Querying.html">ActiveRecord::Querying</a>
  
    <li><a href="../ActiveRecord/Railtie.html">ActiveRecord::Railtie</a>
  
    <li><a href="../ActiveRecord/Railties.html">ActiveRecord::Railties</a>
  
    <li><a href="../ActiveRecord/Railties/ControllerRuntime.html">ActiveRecord::Railties::ControllerRuntime</a>
  
    <li><a href="../ActiveRecord/Railties/ControllerRuntime/ClassMethods.html">ActiveRecord::Railties::ControllerRuntime::ClassMethods</a>
  
    <li><a href="../ActiveRecord/ReadOnlyRecord.html">ActiveRecord::ReadOnlyRecord</a>
  
    <li><a href="../ActiveRecord/ReadonlyAttributes.html">ActiveRecord::ReadonlyAttributes</a>
  
    <li><a href="../ActiveRecord/ReadonlyAttributes/ClassMethods.html">ActiveRecord::ReadonlyAttributes::ClassMethods</a>
  
    <li><a href="../ActiveRecord/RecordInvalid.html">ActiveRecord::RecordInvalid</a>
  
    <li><a href="../ActiveRecord/RecordNotFound.html">ActiveRecord::RecordNotFound</a>
  
    <li><a href="../ActiveRecord/RecordNotSaved.html">ActiveRecord::RecordNotSaved</a>
  
    <li><a href="../ActiveRecord/RecordNotUnique.html">ActiveRecord::RecordNotUnique</a>
  
    <li><a href="../ActiveRecord/Reflection.html">ActiveRecord::Reflection</a>
  
    <li><a href="../ActiveRecord/Reflection/ClassMethods.html">ActiveRecord::Reflection::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Reflection/MacroReflection.html">ActiveRecord::Reflection::MacroReflection</a>
  
    <li><a href="../ActiveRecord/Relation.html">ActiveRecord::Relation</a>
  
    <li><a href="../ActiveRecord/Result.html">ActiveRecord::Result</a>
  
    <li><a href="../ActiveRecord/Rollback.html">ActiveRecord::Rollback</a>
  
    <li><a href="../ActiveRecord/Sanitization.html">ActiveRecord::Sanitization</a>
  
    <li><a href="../ActiveRecord/Sanitization/ClassMethods.html">ActiveRecord::Sanitization::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Schema.html">ActiveRecord::Schema</a>
  
    <li><a href="../ActiveRecord/Scoping.html">ActiveRecord::Scoping</a>
  
    <li><a href="../ActiveRecord/Scoping/ClassMethods.html">ActiveRecord::Scoping::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Scoping/Default.html">ActiveRecord::Scoping::Default</a>
  
    <li><a href="../ActiveRecord/Scoping/Default/ClassMethods.html">ActiveRecord::Scoping::Default::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Scoping/Named.html">ActiveRecord::Scoping::Named</a>
  
    <li><a href="../ActiveRecord/Scoping/Named/ClassMethods.html">ActiveRecord::Scoping::Named::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Serialization.html">ActiveRecord::Serialization</a>
  
    <li><a href="../ActiveRecord/SerializationTypeMismatch.html">ActiveRecord::SerializationTypeMismatch</a>
  
    <li><a href="../ActiveRecord/SessionStore.html">ActiveRecord::SessionStore</a>
  
    <li><a href="../ActiveRecord/SessionStore/Session.html">ActiveRecord::SessionStore::Session</a>
  
    <li><a href="../ActiveRecord/SessionStore/SqlBypass.html">ActiveRecord::SessionStore::SqlBypass</a>
  
    <li><a href="../ActiveRecord/SpawnMethods.html">ActiveRecord::SpawnMethods</a>
  
    <li><a href="../ActiveRecord/StaleObjectError.html">ActiveRecord::StaleObjectError</a>
  
    <li><a href="../ActiveRecord/StatementInvalid.html">ActiveRecord::StatementInvalid</a>
  
    <li><a href="../ActiveRecord/Store.html">ActiveRecord::Store</a>
  
    <li><a href="../ActiveRecord/Store/ClassMethods.html">ActiveRecord::Store::ClassMethods</a>
  
    <li><a href="../ActiveRecord/TestFixtures.html">ActiveRecord::TestFixtures</a>
  
    <li><a href="../ActiveRecord/TestFixtures/ClassMethods.html">ActiveRecord::TestFixtures::ClassMethods</a>
  
    <li><a href="../ActiveRecord/ThrowResult.html">ActiveRecord::ThrowResult</a>
  
    <li><a href="../ActiveRecord/Timestamp.html">ActiveRecord::Timestamp</a>
  
    <li><a href="../ActiveRecord/Transactions.html">ActiveRecord::Transactions</a>
  
    <li><a href="../ActiveRecord/Transactions/ClassMethods.html">ActiveRecord::Transactions::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Translation.html">ActiveRecord::Translation</a>
  
    <li><a href="../ActiveRecord/UnknownAttributeError.html">ActiveRecord::UnknownAttributeError</a>
  
    <li><a href="../ActiveRecord/UnknownPrimaryKey.html">ActiveRecord::UnknownPrimaryKey</a>
  
    <li><a href="../ActiveRecord/Validations.html">ActiveRecord::Validations</a>
  
    <li><a href="../ActiveRecord/Validations/AssociatedValidator.html">ActiveRecord::Validations::AssociatedValidator</a>
  
    <li><a href="../ActiveRecord/Validations/ClassMethods.html">ActiveRecord::Validations::ClassMethods</a>
  
    <li><a href="../ActiveRecord/Validations/UniquenessValidator.html">ActiveRecord::Validations::UniquenessValidator</a>
  
    <li><a href="../ActiveRecord/WrappedDatabaseException.html">ActiveRecord::WrappedDatabaseException</a>
  
    <li><a href="../ActiveSupport.html">ActiveSupport</a>
  
    <li><a href="../ActiveSupport/Autoload.html">ActiveSupport::Autoload</a>
  
    <li><a href="../ActiveSupport/BacktraceCleaner.html">ActiveSupport::BacktraceCleaner</a>
  
    <li><a href="../ActiveSupport/Base64.html">ActiveSupport::Base64</a>
  
    <li><a href="../ActiveSupport/BasicObject.html">ActiveSupport::BasicObject</a>
  
    <li><a href="../ActiveSupport/Benchmarkable.html">ActiveSupport::Benchmarkable</a>
  
    <li><a href="../ActiveSupport/BufferedLogger.html">ActiveSupport::BufferedLogger</a>
  
    <li><a href="../ActiveSupport/BufferedLogger/Severity.html">ActiveSupport::BufferedLogger::Severity</a>
  
    <li><a href="../ActiveSupport/Cache.html">ActiveSupport::Cache</a>
  
    <li><a href="../ActiveSupport/Cache/Entry.html">ActiveSupport::Cache::Entry</a>
  
    <li><a href="../ActiveSupport/Cache/FileStore.html">ActiveSupport::Cache::FileStore</a>
  
    <li><a href="../ActiveSupport/Cache/MemCacheStore.html">ActiveSupport::Cache::MemCacheStore</a>
  
    <li><a href="../ActiveSupport/Cache/MemoryStore.html">ActiveSupport::Cache::MemoryStore</a>
  
    <li><a href="../ActiveSupport/Cache/NullStore.html">ActiveSupport::Cache::NullStore</a>
  
    <li><a href="../ActiveSupport/Cache/Store.html">ActiveSupport::Cache::Store</a>
  
    <li><a href="../ActiveSupport/Cache/Strategy.html">ActiveSupport::Cache::Strategy</a>
  
    <li><a href="../ActiveSupport/Cache/Strategy/LocalCache.html">ActiveSupport::Cache::Strategy::LocalCache</a>
  
    <li><a href="../ActiveSupport/Cache/Strategy/LocalCache/LocalStore.html">ActiveSupport::Cache::Strategy::LocalCache::LocalStore</a>
  
    <li><a href="../ActiveSupport/Callbacks.html">ActiveSupport::Callbacks</a>
  
    <li><a href="../ActiveSupport/Callbacks/ClassMethods.html">ActiveSupport::Callbacks::ClassMethods</a>
  
    <li><a href="../ActiveSupport/Concern.html">ActiveSupport::Concern</a>
  
    <li><a href="../ActiveSupport/Configurable.html">ActiveSupport::Configurable</a>
  
    <li><a href="../ActiveSupport/Configurable/ClassMethods.html">ActiveSupport::Configurable::ClassMethods</a>
  
    <li><a href="../ActiveSupport/Configurable/Configuration.html">ActiveSupport::Configurable::Configuration</a>
  
    <li><a href="../ActiveSupport/Dependencies.html">ActiveSupport::Dependencies</a>
  
    <li><a href="../ActiveSupport/Dependencies/ClassCache.html">ActiveSupport::Dependencies::ClassCache</a>
  
    <li><a href="../ActiveSupport/Dependencies/WatchStack.html">ActiveSupport::Dependencies::WatchStack</a>
  
    <li><a href="../ActiveSupport/Deprecation.html">ActiveSupport::Deprecation</a>
  
    <li><a href="../ActiveSupport/DescendantsTracker.html">ActiveSupport::DescendantsTracker</a>
  
    <li><a href="../ActiveSupport/Duration.html">ActiveSupport::Duration</a>
  
    <li><a href="../ActiveSupport/FileUpdateChecker.html">ActiveSupport::FileUpdateChecker</a>
  
    <li><a href="../ActiveSupport/FileWatcher.html">ActiveSupport::FileWatcher</a>
  
    <li><a href="../ActiveSupport/FileWatcher/Backend.html">ActiveSupport::FileWatcher::Backend</a>
  
    <li><a href="../ActiveSupport/Gzip.html">ActiveSupport::Gzip</a>
  
    <li><a href="../ActiveSupport/Gzip/Stream.html">ActiveSupport::Gzip::Stream</a>
  
    <li><a href="../ActiveSupport/HashWithIndifferentAccess.html">ActiveSupport::HashWithIndifferentAccess</a>
  
    <li><a href="../ActiveSupport/HashWithIndifferentAccess.html">ActiveSupport::HashWithIndifferentAccess</a>
  
    <li><a href="../ActiveSupport/Inflector.html">ActiveSupport::Inflector</a>
  
    <li><a href="../ActiveSupport/Inflector/Inflections.html">ActiveSupport::Inflector::Inflections</a>
  
    <li><a href="../ActiveSupport/InheritableOptions.html">ActiveSupport::InheritableOptions</a>
  
    <li><a href="../ActiveSupport/JSON.html">ActiveSupport::JSON</a>
  
    <li><a href="../ActiveSupport/JSON/Encoding.html">ActiveSupport::JSON::Encoding</a>
  
    <li><a href="../ActiveSupport/JSON/Encoding/CircularReferenceError.html">ActiveSupport::JSON::Encoding::CircularReferenceError</a>
  
    <li><a href="../ActiveSupport/JSON/Encoding/Encoder.html">ActiveSupport::JSON::Encoding::Encoder</a>
  
    <li><a href="../ActiveSupport/JSON/Variable.html">ActiveSupport::JSON::Variable</a>
  
    <li><a href="../ActiveSupport/LogSubscriber.html">ActiveSupport::LogSubscriber</a>
  
    <li><a href="../ActiveSupport/LogSubscriber/TestHelper.html">ActiveSupport::LogSubscriber::TestHelper</a>
  
    <li><a href="../ActiveSupport/LogSubscriber/TestHelper/MockLogger.html">ActiveSupport::LogSubscriber::TestHelper::MockLogger</a>
  
    <li><a href="../ActiveSupport/Memoizable.html">ActiveSupport::Memoizable</a>
  
    <li><a href="../ActiveSupport/Memoizable/InstanceMethods.html">ActiveSupport::Memoizable::InstanceMethods</a>
  
    <li><a href="../ActiveSupport/MessageEncryptor.html">ActiveSupport::MessageEncryptor</a>
  
    <li><a href="../ActiveSupport/MessageEncryptor/InvalidMessage.html">ActiveSupport::MessageEncryptor::InvalidMessage</a>
  
    <li><a href="../ActiveSupport/MessageVerifier.html">ActiveSupport::MessageVerifier</a>
  
    <li><a href="../ActiveSupport/MessageVerifier/InvalidSignature.html">ActiveSupport::MessageVerifier::InvalidSignature</a>
  
    <li><a href="../ActiveSupport/Multibyte.html">ActiveSupport::Multibyte</a>
  
    <li><a href="../ActiveSupport/Multibyte/Chars.html">ActiveSupport::Multibyte::Chars</a>
  
    <li><a href="../ActiveSupport/Multibyte/EncodingError.html">ActiveSupport::Multibyte::EncodingError</a>
  
    <li><a href="../ActiveSupport/Multibyte/Unicode.html">ActiveSupport::Multibyte::Unicode</a>
  
    <li><a href="../ActiveSupport/Multibyte/Unicode/Codepoint.html">ActiveSupport::Multibyte::Unicode::Codepoint</a>
  
    <li><a href="../ActiveSupport/Multibyte/Unicode/UnicodeDatabase.html">ActiveSupport::Multibyte::Unicode::UnicodeDatabase</a>
  
    <li><a href="../ActiveSupport/Notifications.html">ActiveSupport::Notifications</a>
  
    <li><a href="../ActiveSupport/Notifications/Event.html">ActiveSupport::Notifications::Event</a>
  
    <li><a href="../ActiveSupport/Notifications/Fanout.html">ActiveSupport::Notifications::Fanout</a>
  
    <li><a href="../ActiveSupport/Notifications/Instrumenter.html">ActiveSupport::Notifications::Instrumenter</a>
  
    <li><a href="../ActiveSupport/OrderedHash.html">ActiveSupport::OrderedHash</a>
  
    <li><a href="../ActiveSupport/OrderedOptions.html">ActiveSupport::OrderedOptions</a>
  
    <li><a href="../ActiveSupport/Railtie.html">ActiveSupport::Railtie</a>
  
    <li><a href="../ActiveSupport/Rescuable.html">ActiveSupport::Rescuable</a>
  
    <li><a href="../ActiveSupport/Rescuable/ClassMethods.html">ActiveSupport::Rescuable::ClassMethods</a>
  
    <li><a href="../ActiveSupport/SafeBuffer.html">ActiveSupport::SafeBuffer</a>
  
    <li><a href="../ActiveSupport/SafeBuffer/SafeConcatError.html">ActiveSupport::SafeBuffer::SafeConcatError</a>
  
    <li><a href="../ActiveSupport/StringInquirer.html">ActiveSupport::StringInquirer</a>
  
    <li><a href="../ActiveSupport/TaggedLogging.html">ActiveSupport::TaggedLogging</a>
  
    <li><a href="../ActiveSupport/TestCase.html">ActiveSupport::TestCase</a>
  
    <li><a href="../ActiveSupport/Testing.html">ActiveSupport::Testing</a>
  
    <li><a href="../ActiveSupport/Testing/Assertions.html">ActiveSupport::Testing::Assertions</a>
  
    <li><a href="../ActiveSupport/Testing/Declarative.html">ActiveSupport::Testing::Declarative</a>
  
    <li><a href="../ActiveSupport/Testing/Isolation.html">ActiveSupport::Testing::Isolation</a>
  
    <li><a href="../ActiveSupport/Testing/Isolation/Forking.html">ActiveSupport::Testing::Isolation::Forking</a>
  
    <li><a href="../ActiveSupport/Testing/Isolation/MiniTest.html">ActiveSupport::Testing::Isolation::MiniTest</a>
  
    <li><a href="../ActiveSupport/Testing/Isolation/Subprocess.html">ActiveSupport::Testing::Isolation::Subprocess</a>
  
    <li><a href="../ActiveSupport/Testing/Isolation/TestUnit.html">ActiveSupport::Testing::Isolation::TestUnit</a>
  
    <li><a href="../ActiveSupport/Testing/Pending.html">ActiveSupport::Testing::Pending</a>
  
    <li><a href="../ActiveSupport/Testing/Performance.html">ActiveSupport::Testing::Performance</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Benchmarker.html">ActiveSupport::Testing::Performance::Benchmarker</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/ForClassicTestUnit.html">ActiveSupport::Testing::Performance::ForClassicTestUnit</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/ForMiniTest.html">ActiveSupport::Testing::Performance::ForMiniTest</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics.html">ActiveSupport::Testing::Performance::Metrics</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/Amount.html">ActiveSupport::Testing::Performance::Metrics::Amount</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/Base.html">ActiveSupport::Testing::Performance::Metrics::Base</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/CpuTime.html">ActiveSupport::Testing::Performance::Metrics::CpuTime</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/DigitalInformationUnit.html">ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/GcRuns.html">ActiveSupport::Testing::Performance::Metrics::GcRuns</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/GcTime.html">ActiveSupport::Testing::Performance::Metrics::GcTime</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/Memory.html">ActiveSupport::Testing::Performance::Metrics::Memory</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/Objects.html">ActiveSupport::Testing::Performance::Metrics::Objects</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/ProcessTime.html">ActiveSupport::Testing::Performance::Metrics::ProcessTime</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/Time.html">ActiveSupport::Testing::Performance::Metrics::Time</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/UserTime.html">ActiveSupport::Testing::Performance::Metrics::UserTime</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Metrics/WallTime.html">ActiveSupport::Testing::Performance::Metrics::WallTime</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Performer.html">ActiveSupport::Testing::Performance::Performer</a>
  
    <li><a href="../ActiveSupport/Testing/Performance/Profiler.html">ActiveSupport::Testing::Performance::Profiler</a>
  
    <li><a href="../ActiveSupport/Testing/ProxyTestResult.html">ActiveSupport::Testing::ProxyTestResult</a>
  
    <li><a href="../ActiveSupport/Testing/RemoteError.html">ActiveSupport::Testing::RemoteError</a>
  
    <li><a href="../ActiveSupport/Testing/SetupAndTeardown.html">ActiveSupport::Testing::SetupAndTeardown</a>
  
    <li><a href="../ActiveSupport/Testing/SetupAndTeardown/ClassMethods.html">ActiveSupport::Testing::SetupAndTeardown::ClassMethods</a>
  
    <li><a href="../ActiveSupport/Testing/SetupAndTeardown/ForClassicTestUnit.html">ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit</a>
  
    <li><a href="../ActiveSupport/Testing/SetupAndTeardown/ForMiniTest.html">ActiveSupport::Testing::SetupAndTeardown::ForMiniTest</a>
  
    <li><a href="../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>
  
    <li><a href="../ActiveSupport/TimeZone.html">ActiveSupport::TimeZone</a>
  
    <li><a href="../ActiveSupport/XmlMini.html">ActiveSupport::XmlMini</a>
  
    <li><a href="../ActiveSupport/XmlMini_LibXMLSAX.html">ActiveSupport::XmlMini_LibXMLSAX</a>
  
    <li><a href="../ActiveSupport/XmlMini_LibXMLSAX/HashBuilder.html">ActiveSupport::XmlMini_LibXMLSAX::HashBuilder</a>
  
    <li><a href="../ActiveSupport/XmlMini_NokogiriSAX.html">ActiveSupport::XmlMini_NokogiriSAX</a>
  
    <li><a href="../ActiveSupport/XmlMini_NokogiriSAX/HashBuilder.html">ActiveSupport::XmlMini_NokogiriSAX::HashBuilder</a>
  
    <li><a href="../ActionController.html">ActionController</a>
  
    <li><a href="../ActionController/Base.html">ActionController::Base</a>
  
    <li><a href="../ActionController/Caching.html">ActionController::Caching</a>
  
    <li><a href="../ActionController/Caching/Actions.html">ActionController::Caching::Actions</a>
  
    <li><a href="../ActionController/Caching/Actions/ActionCachePath.html">ActionController::Caching::Actions::ActionCachePath</a>
  
    <li><a href="../ActionController/Caching/Actions/ClassMethods.html">ActionController::Caching::Actions::ClassMethods</a>
  
    <li><a href="../ActionController/Caching/ConfigMethods.html">ActionController::Caching::ConfigMethods</a>
  
    <li><a href="../ActionController/Caching/Fragments.html">ActionController::Caching::Fragments</a>
  
    <li><a href="../ActionController/Caching/Pages.html">ActionController::Caching::Pages</a>
  
    <li><a href="../ActionController/Caching/Pages/ClassMethods.html">ActionController::Caching::Pages::ClassMethods</a>
  
    <li><a href="../ActionController/Caching/Sweeping.html">ActionController::Caching::Sweeping</a>
  
    <li><a href="../ActionController/Compatibility.html">ActionController::Compatibility</a>
  
    <li><a href="../ActionController/ConditionalGet.html">ActionController::ConditionalGet</a>
  
    <li><a href="../ActionController/Cookies.html">ActionController::Cookies</a>
  
    <li><a href="../ActionController/DataStreaming.html">ActionController::DataStreaming</a>
  
    <li><a href="../ActionController/Flash.html">ActionController::Flash</a>
  
    <li><a href="../ActionController/ForceSSL.html">ActionController::ForceSSL</a>
  
    <li><a href="../ActionController/ForceSSL/ClassMethods.html">ActionController::ForceSSL::ClassMethods</a>
  
    <li><a href="../ActionController/Head.html">ActionController::Head</a>
  
    <li><a href="../ActionController/Helpers.html">ActionController::Helpers</a>
  
    <li><a href="../ActionController/Helpers/ClassMethods.html">ActionController::Helpers::ClassMethods</a>
  
    <li><a href="../ActionController/HideActions.html">ActionController::HideActions</a>
  
    <li><a href="../ActionController/HideActions/ClassMethods.html">ActionController::HideActions::ClassMethods</a>
  
    <li><a href="../ActionController/HttpAuthentication.html">ActionController::HttpAuthentication</a>
  
    <li><a href="../ActionController/HttpAuthentication/Basic.html">ActionController::HttpAuthentication::Basic</a>
  
    <li><a href="../ActionController/HttpAuthentication/Basic/ControllerMethods.html">ActionController::HttpAuthentication::Basic::ControllerMethods</a>
  
    <li><a href="../ActionController/HttpAuthentication/Basic/ControllerMethods/ClassMethods.html">ActionController::HttpAuthentication::Basic::ControllerMethods::ClassMethods</a>
  
    <li><a href="../ActionController/HttpAuthentication/Digest.html">ActionController::HttpAuthentication::Digest</a>
  
    <li><a href="../ActionController/HttpAuthentication/Digest/ControllerMethods.html">ActionController::HttpAuthentication::Digest::ControllerMethods</a>
  
    <li><a href="../ActionController/HttpAuthentication/Token.html">ActionController::HttpAuthentication::Token</a>
  
    <li><a href="../ActionController/HttpAuthentication/Token/ControllerMethods.html">ActionController::HttpAuthentication::Token::ControllerMethods</a>
  
    <li><a href="../ActionController/ImplicitRender.html">ActionController::ImplicitRender</a>
  
    <li><a href="../ActionController/Instrumentation.html">ActionController::Instrumentation</a>
  
    <li><a href="../ActionController/Instrumentation/ClassMethods.html">ActionController::Instrumentation::ClassMethods</a>
  
    <li><a href="../ActionController/LogSubscriber.html">ActionController::LogSubscriber</a>
  
    <li><a href="../ActionController/Metal.html">ActionController::Metal</a>
  
    <li><a href="../ActionController/Middleware.html">ActionController::Middleware</a>
  
    <li><a href="../ActionController/Middleware/ActionMiddleware.html">ActionController::Middleware::ActionMiddleware</a>
  
    <li><a href="../ActionController/MimeResponds.html">ActionController::MimeResponds</a>
  
    <li><a href="../ActionController/MimeResponds/ClassMethods.html">ActionController::MimeResponds::ClassMethods</a>
  
    <li><a href="../ActionController/ParamsWrapper.html">ActionController::ParamsWrapper</a>
  
    <li><a href="../ActionController/ParamsWrapper/ClassMethods.html">ActionController::ParamsWrapper::ClassMethods</a>
  
    <li><a href="../ActionController/RackDelegation.html">ActionController::RackDelegation</a>
  
    <li><a href="../ActionController/Railtie.html">ActionController::Railtie</a>
  
    <li><a href="../ActionController/Railties.html">ActionController::Railties</a>
  
    <li><a href="../ActionController/Railties/Paths.html">ActionController::Railties::Paths</a>
  
    <li><a href="../ActionController/RecordIdentifier.html">ActionController::RecordIdentifier</a>
  
    <li><a href="../ActionController/Redirecting.html">ActionController::Redirecting</a>
  
    <li><a href="../ActionController/Renderers.html">ActionController::Renderers</a>
  
    <li><a href="../ActionController/Renderers/All.html">ActionController::Renderers::All</a>
  
    <li><a href="../ActionController/Renderers/ClassMethods.html">ActionController::Renderers::ClassMethods</a>
  
    <li><a href="../ActionController/Rendering.html">ActionController::Rendering</a>
  
    <li><a href="../ActionController/RequestForgeryProtection.html">ActionController::RequestForgeryProtection</a>
  
    <li><a href="../ActionController/RequestForgeryProtection/ClassMethods.html">ActionController::RequestForgeryProtection::ClassMethods</a>
  
    <li><a href="../ActionController/Rescue.html">ActionController::Rescue</a>
  
    <li><a href="../ActionController/Responder.html">ActionController::Responder</a>
  
    <li><a href="../ActionController/SessionManagement.html">ActionController::SessionManagement</a>
  
    <li><a href="../ActionController/SessionManagement/ClassMethods.html">ActionController::SessionManagement::ClassMethods</a>
  
    <li><a href="../ActionController/Streaming.html">ActionController::Streaming</a>
  
    <li><a href="../ActionController/TemplateAssertions.html">ActionController::TemplateAssertions</a>
  
    <li><a href="../ActionController/TestCase.html">ActionController::TestCase</a>
  
    <li><a href="../ActionController/TestCase/Behavior.html">ActionController::TestCase::Behavior</a>
  
    <li><a href="../ActionController/TestCase/Behavior/ClassMethods.html">ActionController::TestCase::Behavior::ClassMethods</a>
  
    <li><a href="../ActionController/TestCase/RaiseActionExceptions.html">ActionController::TestCase::RaiseActionExceptions</a>
  
    <li><a href="../ActionController/TestResponse.html">ActionController::TestResponse</a>
  
    <li><a href="../ActionController/Testing.html">ActionController::Testing</a>
  
    <li><a href="../ActionController/Testing/ClassMethods.html">ActionController::Testing::ClassMethods</a>
  
    <li><a href="../ActionController/UrlFor.html">ActionController::UrlFor</a>
  
    <li><a href="../ActionView.html">ActionView</a>
  
    <li><a href="../ActionView/ActionView.html">ActionView::ActionView</a>
  
    <li><a href="../ActionView/ActionView/ActionView.html">ActionView::ActionView::ActionView</a>
  
    <li><a href="../ActionView/ActionView/ActionView/Base.html">ActionView::ActionView::ActionView::Base</a>
  
    <li><a href="../ActionView/Base.html">ActionView::Base</a>
  
    <li><a href="../ActionView/Context.html">ActionView::Context</a>
  
    <li><a href="../ActionView/FileSystemResolver.html">ActionView::FileSystemResolver</a>
  
    <li><a href="../ActionView/FixtureResolver.html">ActionView::FixtureResolver</a>
  
    <li><a href="../ActionView/Helpers.html">ActionView::Helpers</a>
  
    <li><a href="../ActionView/Helpers/ActiveModelHelper.html">ActionView::Helpers::ActiveModelHelper</a>
  
    <li><a href="../ActionView/Helpers/ActiveModelInstanceTag.html">ActionView::Helpers::ActiveModelInstanceTag</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper.html">ActionView::Helpers::AssetTagHelper</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/AssetIncludeTag.html">ActionView::Helpers::AssetTagHelper::AssetIncludeTag</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/JavascriptIncludeTag.html">ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers.html">ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers/ClassMethods.html">ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers::ClassMethods</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/StylesheetIncludeTag.html">ActionView::Helpers::AssetTagHelper::StylesheetIncludeTag</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/StylesheetTagHelpers.html">ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers</a>
  
    <li><a href="../ActionView/Helpers/AssetTagHelper/StylesheetTagHelpers/ClassMethods.html">ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers::ClassMethods</a>
  
    <li><a href="../ActionView/Helpers/AtomFeedHelper.html">ActionView::Helpers::AtomFeedHelper</a>
  
    <li><a href="../ActionView/Helpers/AtomFeedHelper/AtomBuilder.html">ActionView::Helpers::AtomFeedHelper::AtomBuilder</a>
  
    <li><a href="../ActionView/Helpers/AtomFeedHelper/AtomFeedBuilder.html">ActionView::Helpers::AtomFeedHelper::AtomFeedBuilder</a>
  
    <li><a href="../ActionView/Helpers/CacheHelper.html">ActionView::Helpers::CacheHelper</a>
  
    <li><a href="../ActionView/Helpers/CaptureHelper.html">ActionView::Helpers::CaptureHelper</a>
  
    <li><a href="../ActionView/Helpers/CsrfHelper.html">ActionView::Helpers::CsrfHelper</a>
  
    <li><a href="../ActionView/Helpers/DateHelper.html">ActionView::Helpers::DateHelper</a>
  
    <li><a href="../ActionView/Helpers/DateHelperInstanceTag.html">ActionView::Helpers::DateHelperInstanceTag</a>
  
    <li><a href="../ActionView/Helpers/DebugHelper.html">ActionView::Helpers::DebugHelper</a>
  
    <li><a href="../ActionView/Helpers/FormBuilder.html">ActionView::Helpers::FormBuilder</a>
  
    <li><a href="../ActionView/Helpers/FormHelper.html">ActionView::Helpers::FormHelper</a>
  
    <li><a href="../ActionView/Helpers/FormOptionsHelper.html">ActionView::Helpers::FormOptionsHelper</a>
  
    <li><a href="../ActionView/Helpers/FormTagHelper.html">ActionView::Helpers::FormTagHelper</a>
  
    <li><a href="../ActionView/Helpers/InstanceTag.html">ActionView::Helpers::InstanceTag</a>
  
    <li><a href="../ActionView/Helpers/JavaScriptHelper.html">ActionView::Helpers::JavaScriptHelper</a>
  
    <li><a href="../ActionView/Helpers/NumberHelper.html">ActionView::Helpers::NumberHelper</a>
  
    <li><a href="../ActionView/Helpers/NumberHelper/InvalidNumberError.html">ActionView::Helpers::NumberHelper::InvalidNumberError</a>
  
    <li><a href="../ActionView/Helpers/OutputSafetyHelper.html">ActionView::Helpers::OutputSafetyHelper</a>
  
    <li><a href="../ActionView/Helpers/RecordTagHelper.html">ActionView::Helpers::RecordTagHelper</a>
  
    <li><a href="../ActionView/Helpers/RenderingHelper.html">ActionView::Helpers::RenderingHelper</a>
  
    <li><a href="../ActionView/Helpers/SanitizeHelper.html">ActionView::Helpers::SanitizeHelper</a>
  
    <li><a href="../ActionView/Helpers/TagHelper.html">ActionView::Helpers::TagHelper</a>
  
    <li><a href="../ActionView/Helpers/TextHelper.html">ActionView::Helpers::TextHelper</a>
  
    <li><a href="../ActionView/Helpers/TranslationHelper.html">ActionView::Helpers::TranslationHelper</a>
  
    <li><a href="../ActionView/Helpers/UrlHelper.html">ActionView::Helpers::UrlHelper</a>
  
    <li><a href="../ActionView/LogSubscriber.html">ActionView::LogSubscriber</a>
  
    <li><a href="../ActionView/LookupContext.html">ActionView::LookupContext</a>
  
    <li><a href="../ActionView/LookupContext/DetailsCache.html">ActionView::LookupContext::DetailsCache</a>
  
    <li><a href="../ActionView/LookupContext/ViewPaths.html">ActionView::LookupContext::ViewPaths</a>
  
    <li><a href="../ActionView/NullResolver.html">ActionView::NullResolver</a>
  
    <li><a href="../ActionView/PartialRenderer.html">ActionView::PartialRenderer</a>
  
    <li><a href="../ActionView/Railtie.html">ActionView::Railtie</a>
  
    <li><a href="../ActionView/Renderer.html">ActionView::Renderer</a>
  
    <li><a href="../ActionView/Resolver.html">ActionView::Resolver</a>
  
    <li><a href="../ActionView/Resolver/Path.html">ActionView::Resolver::Path</a>
  
    <li><a href="../ActionView/Template.html">ActionView::Template</a>
  
    <li><a href="../ActionView/Template/Handlers.html">ActionView::Template::Handlers</a>
  
    <li><a href="../ActionView/Template/Handlers/Builder.html">ActionView::Template::Handlers::Builder</a>
  
    <li><a href="../ActionView/Template/Handlers/ERB.html">ActionView::Template::Handlers::ERB</a>
  
    <li><a href="../ActionView/Template/Handlers/Erubis.html">ActionView::Template::Handlers::Erubis</a>
  
    <li><a href="../ActionView/TestCase.html">ActionView::TestCase</a>
  
    <li><a href="../ActionView/TestCase/Behavior.html">ActionView::TestCase::Behavior</a>
  
    <li><a href="../ActionView/TestCase/Behavior/ClassMethods.html">ActionView::TestCase::Behavior::ClassMethods</a>
  
    <li><a href="../ActionView/TestCase/Behavior/Locals.html">ActionView::TestCase::Behavior::Locals</a>
  
    <li><a href="../ActionView/TestCase/TestController.html">ActionView::TestCase::TestController</a>
  
    <li><a href="../ActiveModel.html">ActiveModel</a>
  
    <li><a href="../ActiveModel/AttributeMethods.html">ActiveModel::AttributeMethods</a>
  
    <li><a href="../ActiveModel/AttributeMethods/ClassMethods.html">ActiveModel::AttributeMethods::ClassMethods</a>
  
    <li><a href="../ActiveModel/AttributeMethods/ClassMethods/AttributeMethodMatcher.html">ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher</a>
  
    <li><a href="../ActiveModel/BlockValidator.html">ActiveModel::BlockValidator</a>
  
    <li><a href="../ActiveModel/Callbacks.html">ActiveModel::Callbacks</a>
  
    <li><a href="../ActiveModel/Conversion.html">ActiveModel::Conversion</a>
  
    <li><a href="../ActiveModel/Dirty.html">ActiveModel::Dirty</a>
  
    <li><a href="../ActiveModel/EachValidator.html">ActiveModel::EachValidator</a>
  
    <li><a href="../ActiveModel/Errors.html">ActiveModel::Errors</a>
  
    <li><a href="../ActiveModel/Lint.html">ActiveModel::Lint</a>
  
    <li><a href="../ActiveModel/Lint/Tests.html">ActiveModel::Lint::Tests</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity.html">ActiveModel::MassAssignmentSecurity</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/BlackList.html">ActiveModel::MassAssignmentSecurity::BlackList</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/ClassMethods.html">ActiveModel::MassAssignmentSecurity::ClassMethods</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/Error.html">ActiveModel::MassAssignmentSecurity::Error</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/LoggerSanitizer.html">ActiveModel::MassAssignmentSecurity::LoggerSanitizer</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/PermissionSet.html">ActiveModel::MassAssignmentSecurity::PermissionSet</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/Sanitizer.html">ActiveModel::MassAssignmentSecurity::Sanitizer</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/StrictSanitizer.html">ActiveModel::MassAssignmentSecurity::StrictSanitizer</a>
  
    <li><a href="../ActiveModel/MassAssignmentSecurity/WhiteList.html">ActiveModel::MassAssignmentSecurity::WhiteList</a>
  
    <li><a href="../ActiveModel/MissingAttributeError.html">ActiveModel::MissingAttributeError</a>
  
    <li><a href="../ActiveModel/Name.html">ActiveModel::Name</a>
  
    <li><a href="../ActiveModel/Naming.html">ActiveModel::Naming</a>
  
    <li><a href="../ActiveModel/Observer.html">ActiveModel::Observer</a>
  
    <li><a href="../ActiveModel/ObserverArray.html">ActiveModel::ObserverArray</a>
  
    <li><a href="../ActiveModel/Observing.html">ActiveModel::Observing</a>
  
    <li><a href="../ActiveModel/Observing/ClassMethods.html">ActiveModel::Observing::ClassMethods</a>
  
    <li><a href="../ActiveModel/SecurePassword.html">ActiveModel::SecurePassword</a>
  
    <li><a href="../ActiveModel/SecurePassword/ClassMethods.html">ActiveModel::SecurePassword::ClassMethods</a>
  
    <li><a href="../ActiveModel/SecurePassword/InstanceMethodsOnActivation.html">ActiveModel::SecurePassword::InstanceMethodsOnActivation</a>
  
    <li><a href="../ActiveModel/Serialization.html">ActiveModel::Serialization</a>
  
    <li><a href="../ActiveModel/Serializers.html">ActiveModel::Serializers</a>
  
    <li><a href="../ActiveModel/Serializers/JSON.html">ActiveModel::Serializers::JSON</a>
  
    <li><a href="../ActiveModel/Serializers/Xml.html">ActiveModel::Serializers::Xml</a>
  
    <li><a href="../ActiveModel/StrictValidationFailed.html">ActiveModel::StrictValidationFailed</a>
  
    <li><a href="../ActiveModel/Translation.html">ActiveModel::Translation</a>
  
    <li><a href="../ActiveModel/Validations.html">ActiveModel::Validations</a>
  
    <li><a href="../ActiveModel/Validations/AcceptanceValidator.html">ActiveModel::Validations::AcceptanceValidator</a>
  
    <li><a href="../ActiveModel/Validations/Callbacks.html">ActiveModel::Validations::Callbacks</a>
  
    <li><a href="../ActiveModel/Validations/Callbacks/ClassMethods.html">ActiveModel::Validations::Callbacks::ClassMethods</a>
  
    <li><a href="../ActiveModel/Validations/ClassMethods.html">ActiveModel::Validations::ClassMethods</a>
  
    <li><a href="../ActiveModel/Validations/ConfirmationValidator.html">ActiveModel::Validations::ConfirmationValidator</a>
  
    <li><a href="../ActiveModel/Validations/ExclusionValidator.html">ActiveModel::Validations::ExclusionValidator</a>
  
    <li><a href="../ActiveModel/Validations/FormatValidator.html">ActiveModel::Validations::FormatValidator</a>
  
    <li><a href="../ActiveModel/Validations/HelperMethods.html">ActiveModel::Validations::HelperMethods</a>
  
    <li><a href="../ActiveModel/Validations/InclusionValidator.html">ActiveModel::Validations::InclusionValidator</a>
  
    <li><a href="../ActiveModel/Validations/LengthValidator.html">ActiveModel::Validations::LengthValidator</a>
  
    <li><a href="../ActiveModel/Validations/NumericalityValidator.html">ActiveModel::Validations::NumericalityValidator</a>
  
    <li><a href="../ActiveModel/Validations/PresenceValidator.html">ActiveModel::Validations::PresenceValidator</a>
  
    <li><a href="../ActiveModel/Validations/WithValidator.html">ActiveModel::Validations::WithValidator</a>
  
    <li><a href="../ActiveModel/Validator.html">ActiveModel::Validator</a>
  
    <li><a href="../ActiveResource.html">ActiveResource</a>
  
    <li><a href="../ActiveResource/Base.html">ActiveResource::Base</a>
  
    <li><a href="../ActiveResource/Connection.html">ActiveResource::Connection</a>
  
    <li><a href="../ActiveResource/CustomMethods.html">ActiveResource::CustomMethods</a>
  
    <li><a href="../ActiveResource/CustomMethods/ClassMethods.html">ActiveResource::CustomMethods::ClassMethods</a>
  
    <li><a href="../ActiveResource/Errors.html">ActiveResource::Errors</a>
  
    <li><a href="../ActiveResource/Formats.html">ActiveResource::Formats</a>
  
    <li><a href="../ActiveResource/Formats/JsonFormat.html">ActiveResource::Formats::JsonFormat</a>
  
    <li><a href="../ActiveResource/Formats/XmlFormat.html">ActiveResource::Formats::XmlFormat</a>
  
    <li><a href="../ActiveResource/HttpMock.html">ActiveResource::HttpMock</a>
  
    <li><a href="../ActiveResource/InvalidRequestError.html">ActiveResource::InvalidRequestError</a>
  
    <li><a href="../ActiveResource/LogSubscriber.html">ActiveResource::LogSubscriber</a>
  
    <li><a href="../ActiveResource/Observing.html">ActiveResource::Observing</a>
  
    <li><a href="../ActiveResource/Railtie.html">ActiveResource::Railtie</a>
  
    <li><a href="../ActiveResource/Request.html">ActiveResource::Request</a>
  
    <li><a href="../ActiveResource/Response.html">ActiveResource::Response</a>
  
    <li><a href="../ActiveResource/SSLError.html">ActiveResource::SSLError</a>
  
    <li><a href="../ActiveResource/TimeoutError.html">ActiveResource::TimeoutError</a>
  
    <li><a href="../ActiveResource/Validations.html">ActiveResource::Validations</a>
  
    <li><a href="../HTML.html">HTML</a>
  
    <li><a href="../HTML/FullSanitizer.html">HTML::FullSanitizer</a>
  
    <li><a href="../HTML/LinkSanitizer.html">HTML::LinkSanitizer</a>
  
    <li><a href="../HTML/Sanitizer.html">HTML::Sanitizer</a>
  
    <li><a href="../HTML/Selector.html">HTML::Selector</a>
  
    <li><a href="../HTML/Tag.html">HTML::Tag</a>
  
    <li><a href="../HTML/WhiteListSanitizer.html">HTML::WhiteListSanitizer</a>
  
    <li><a href="../Mysql.html">Mysql</a>
  
    <li><a href="../Mysql/Result.html">Mysql::Result</a>
  
    <li><a href="../Mysql/Stmt.html">Mysql::Stmt</a>
  
    <li><a href="../Mysql/Time.html">Mysql::Time</a>
  
    <li><a href="../Test.html">Test</a>
  
    <li><a href="../Test/Unit.html">Test::Unit</a>
  
    <li><a href="../Test/Unit/Collector.html">Test::Unit::Collector</a>
  
    <li><a href="../Test/Unit/Collector/ObjectSpace.html">Test::Unit::Collector::ObjectSpace</a>
  
    <li><a href="../I18n.html">I18n</a>
  
    <li><a href="../I18n/ExceptionHandler.html">I18n::ExceptionHandler</a>
  
    <li><a href="../I18n/Railtie.html">I18n::Railtie</a>
  
    <li><a href="../Object.html">Object</a>
  
    <li><a href="../ActiveSupport/HashWithIndifferentAccess.html">Object::HashWithIndifferentAccess</a>
  
    <li><a href="../LoadError.html">Object::MissingSourceFile</a>
  
    <li><a href="../ActionMailer.html">ActionMailer</a>
  
    <li><a href="../ActionMailer/Base.html">ActionMailer::Base</a>
  
    <li><a href="../ArJdbcMySQL.html">ArJdbcMySQL</a>
  
    <li><a href="../ArJdbcMySQL/Error.html">ArJdbcMySQL::Error</a>
  
    <li><a href="../ERB.html">ERB</a>
  
    <li><a href="../ERB/Util.html">ERB::Util</a>
  
    <li><a href="../LoadError.html">LoadError</a>
  
    <li><a href="../LoadError.html">LoadError</a>
  
    <li><a href="../Logger.html">Logger</a>
  
    <li><a href="../Logger/SimpleFormatter.html">Logger::SimpleFormatter</a>
  
    <li><a href="../Array.html">Array</a>
  
    <li><a href="../Base64.html">Base64</a>
  
    <li><a href="../Benchmark.html">Benchmark</a>
  
    <li><a href="../BigDecimal.html">BigDecimal</a>
  
    <li><a href="../Class.html">Class</a>
  
    <li><a href="../Date.html">Date</a>
  
    <li><a href="../DateTime.html">DateTime</a>
  
    <li><a href="../Enumerable.html">Enumerable</a>
  
    <li><a href="../FalseClass.html">FalseClass</a>
  
    <li><a href="../File.html">File</a>
  
    <li><a href="../Float.html">Float</a>
  
    <li><a href="../Hash.html">Hash</a>
  
    <li><a href="../Integer.html">Integer</a>
  
    <li><a href="../Kernel.html">Kernel</a>
  
    <li><a href="../Module.html">Module</a>
  
    <li><a href="../NameError.html">NameError</a>
  
    <li><a href="../NilClass.html">NilClass</a>
  
    <li><a href="../Numeric.html">Numeric</a>
  
    <li><a href="../Process.html">Process</a>
  
    <li><a href="../QualifiedConstUtils.html">QualifiedConstUtils</a>
  
    <li><a href="../Rails.html">Rails</a>
  
    <li><a href="../Range.html">Range</a>
  
    <li><a href="../Regexp.html">Regexp</a>
  
    <li><a href="../String.html">String</a>
  
    <li><a href="../Symbol.html">Symbol</a>
  
    <li><a href="../Time.html">Time</a>
  
    <li><a href="../TrueClass.html">TrueClass</a>
  
    <li><a href="../URI.html">URI</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class HTML::Selector</h1>

  <div id="description" class="description">
    
<p>Selects <a href="../HTML.html">HTML</a> elements using CSS 2 selectors.</p>

<p>The <code>Selector</code> class uses CSS selector expressions to match and
select <a href="../HTML.html">HTML</a> elements.</p>

<p>For example:</p>

<pre>selector = HTML::Selector.new &quot;form.login[action=/login]&quot;</pre>

<p>creates a new selector that matches any <code>form</code> element with the
class <code>login</code> and an attribute <code>action</code> with the
value <code>/login</code>.</p>

<h3 id="label-Matching+Elements">Matching Elements</h3>

<p>Use the <a href="Selector.html#method-i-match">match</a> method to
determine if an element matches the selector.</p>

<p>For simple selectors, the method returns an array with that element, or
<code>nil</code> if the element does not match. For complex selectors (see
below) the method returns an array with all matched elements, of
<code>nil</code> if no match found.</p>

<p>For example:</p>

<pre>if selector.match(element)
  puts &quot;Element is a login form&quot;
end</pre>

<h3 id="label-Selecting+Elements">Selecting Elements</h3>

<p>Use the <a href="Selector.html#method-i-select">select</a> method to select
all matching elements starting with one element and going through all
children in depth-first order.</p>

<p>This method returns an array of all matching elements, an empty array if no
match is found</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-identifier">selector</span> = <span class="ruby-constant">HTML</span><span class="ruby-operator">::</span><span class="ruby-constant">Selector</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;input[type=text]&quot;</span>
<span class="ruby-identifier">matches</span> = <span class="ruby-identifier">selector</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">element</span>)
<span class="ruby-identifier">matches</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Found text field with name #{match.attributes['name']}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="label-Expressions">Expressions</h3>

<p>Selectors can match elements using any of the following criteria:</p>
<ul><li>
<p><code>name</code> -- Match an element based on its name (tag name). For
example, <code>p</code> to match a paragraph. You can use <code>*</code> to
match any element.</p>
</li><li>
<p><code>#id</code> -- Match an element based on its identifier (the
<code>id</code> attribute). For example, <code>#page</code>.</p>
</li><li>
<p><code>.class</code> -- Match an element based on its class name, all class
names if more than one specified.</p>
</li><li>
<p><code>[attr]</code> -- Match an element that has the specified attribute.</p>
</li><li>
<p><code>[attr=value]</code> -- Match an element that has the specified
attribute and value. (More operators are supported see below)</p>
</li><li>
<p><code>:pseudo-class</code> -- Match an element based on a pseudo class,
such as <code>:nth-child</code> and <code>:empty</code>.</p>
</li><li>
<p><code>:not(expr)</code> -- Match an element that does not match the
negation expression.</p>
</li></ul>

<p>When using a combination of the above, the element name comes first
followed by identifier, class names, attributes, pseudo classes and
negation in any order. Do not separate these parts with spaces! Space
separation is used for descendant selectors.</p>

<p>For example:</p>

<pre>selector = HTML::Selector.new &quot;form.login[action=/login]&quot;</pre>

<p>The matched element must be of type <code>form</code> and have the class
<code>login</code>. It may have other classes, but the class
<code>login</code> is required to match. It must also have an attribute
called <code>action</code> with the value <code>/login</code>.</p>

<p>This selector will match the following element:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">form</span> <span class="ruby-keyword">class</span>=<span class="ruby-string">&quot;login form&quot;</span> <span class="ruby-identifier">method</span>=<span class="ruby-string">&quot;post&quot;</span> <span class="ruby-identifier">action</span>=<span class="ruby-string">&quot;/login&quot;</span><span class="ruby-operator">&gt;</span>
</pre>

<p>but will not match the element:</p>

<pre>&lt;form method=&quot;post&quot; action=&quot;/logout&quot;&gt;</pre>

<h3 id="label-Attribute+Values">Attribute Values</h3>

<p>Several operators are supported for matching attributes:</p>
<ul><li>
<p><code>name</code> -- The element must have an attribute with that name.</p>
</li><li>
<p><code>name=value</code> -- The element must have an attribute with that
name and value.</p>
</li><li>
<p><code>name^=value</code> -- The attribute value must start with the
specified value.</p>
</li><li>
<p><code>name$=value</code> -- The attribute value must end with the specified
value.</p>
</li><li>
<p><code>name*=value</code> -- The attribute value must contain the specified
value.</p>
</li><li>
<p><code>name~=word</code> -- The attribute value must contain the specified
word (space separated).</p>
</li><li>
<p><code>name|=word</code> -- The attribute value must start with specified
word.</p>
</li></ul>

<p>For example, the following two selectors match the same element:</p>

<pre>#my_id
[id=my_id]</pre>

<p>and so do the following two selectors:</p>

<pre class="ruby">.<span class="ruby-identifier">my_class</span>
[<span class="ruby-keyword">class</span><span class="ruby-operator">~</span>=<span class="ruby-identifier">my_class</span>]
</pre>

<h3 id="label-Alternatives%2C+siblings%2C+children">Alternatives, siblings, children</h3>

<p>Complex selectors use a combination of expressions to match elements:</p>
<ul><li>
<p><code>expr1 expr2</code> -- Match any element against the second expression
if it has some parent element that matches the first expression.</p>
</li><li>
<p><code>expr1 &gt; expr2</code> -- Match any element against the second
expression if it is the child of an element that matches the first
expression.</p>
</li><li>
<p><code>expr1 + expr2</code> -- Match any element against the second
expression if it immediately follows an element that matches the first
expression.</p>
</li><li>
<p><code>expr1 ~ expr2</code> -- Match any element against the second
expression that comes after an element that matches the first expression.</p>
</li><li>
<p><code>expr1, expr2</code> -- Match any element against the first
expression, or against the second expression.</p>
</li></ul>

<p>Since children and sibling selectors may match more than one element given
the first element, the <a href="Selector.html#method-i-match">match</a>
method may return more than one match.</p>

<h3 id="label-Pseudo+classes">Pseudo classes</h3>

<p>Pseudo classes were introduced in CSS 3. They are most often used to select
elements in a given position:</p>
<ul><li>
<p><code>:root</code> -- Match the element only if it is the root element (no
parent element).</p>
</li><li>
<p><code>:empty</code> -- Match the element only if it has no child elements,
and no text content.</p>
</li><li>
<p><code>:content(string)</code> -- Match the element only if it has
<code>string</code> as its text content (ignoring leading and trailing
whitespace).</p>
</li><li>
<p><code>:only-child</code> -- Match the element if it is the only child
(element) of its parent element.</p>
</li><li>
<p><code>:only-of-type</code> -- Match the element if it is the only child
(element) of its parent element and its type.</p>
</li><li>
<p><code>:first-child</code> -- Match the element if it is the first child
(element) of its parent element.</p>
</li><li>
<p><code>:first-of-type</code> -- Match the element if it is the first child
(element) of its parent element of its type.</p>
</li><li>
<p><code>:last-child</code> -- Match the element if it is the last child
(element) of its parent element.</p>
</li><li>
<p><code>:last-of-type</code> -- Match the element if it is the last child
(element) of its parent element of its type.</p>
</li><li>
<p><code>:nth-child(b)</code> -- Match the element if it is the b-th child
(element) of its parent element. The value <code>b</code> specifies its
index, starting with 1.</p>
</li><li>
<p><code>:nth-child(an+b)</code> -- Match the element if it is the b-th child
(element) in each group of <code>a</code> child elements of its parent
element.</p>
</li><li>
<p><code>:nth-child(-an+b)</code> -- Match the element if it is the first
child (element) in each group of <code>a</code> child elements, up to the
first <code>b</code> child elements of its parent element.</p>
</li><li>
<p><code>:nth-child(odd)</code> -- Match element in the odd position (i.e.
first, third). Same as <code>:nth-child(2n+1)</code>.</p>
</li><li>
<p><code>:nth-child(even)</code> -- Match element in the even position (i.e.
second, fourth). Same as <code>:nth-child(2n+2)</code>.</p>
</li><li>
<p><code>:nth-of-type(..)</code> -- As above, but only counts elements of its
type.</p>
</li><li>
<p><code>:nth-last-child(..)</code> -- As above, but counts from the last
child.</p>
</li><li>
<p><code>:nth-last-of-type(..)</code> -- As above, but counts from the last
child and only elements of its type.</p>
</li><li>
<p><code>:not(selector)</code> -- Match the element only if the element does
not match the simple selector.</p>
</li></ul>

<p>As you can see, &lt;tt&gt;:nth-child&lt;tt&gt; pseudo class and its variant
can get quite tricky and the CSS specification doesn’t do a much better job
explaining it. But after reading the examples and trying a few
combinations, it’s easy to figure out.</p>

<p>For example:</p>

<pre>table tr:nth-child(odd)</pre>

<p>Selects every second row in the table starting with the first one.</p>

<pre>div p:nth-child(4)</pre>

<p>Selects the fourth paragraph in the <code>div</code>, but not if the
<code>div</code> contains other elements, since those are also counted.</p>

<pre>div p:nth-of-type(4)</pre>

<p>Selects the fourth paragraph in the <code>div</code>, counting only
paragraphs, and ignoring all other elements.</p>

<pre>div p:nth-of-type(-n+4)</pre>

<p>Selects the first four paragraphs, ignoring all others.</p>

<p>And you can always select an element that matches one set of rules but not
another using <code>:not</code>. For example:</p>

<pre>p:not(.post)</pre>

<p>Matches all paragraphs that do not have the class <code>.post</code>.</p>

<h3 id="label-Substitution+Values">Substitution Values</h3>

<p>You can use substitution with identifiers, class names and element values.
A substitution takes the form of a question mark (<code>?</code>) and uses
the next value in the argument list following the CSS expression.</p>

<p>The substitution value may be a string or a regular expression. All other
values are converted to strings.</p>

<p>For example:</p>

<pre>selector = HTML::Selector.new &quot;#?&quot;, /^\d+$/</pre>

<p>matches any element whose identifier consists of one or more digits.</p>

<p>See <a
href="http://www.w3.org/TR/css3-selectors/">www.w3.org/TR/css3-selectors/</a></p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-for_class" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            for_class(cls) &rarr; selector
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Creates a new selector for the given class name.</p>
          

          
          <div class="method-source-code" id="for_class-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 216</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">for_class</span>(<span class="ruby-identifier">cls</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&quot;.?&quot;</span>, <span class="ruby-identifier">cls</span>])
<span class="ruby-keyword">end</span></pre>
          </div><!-- for_class-source -->
          
        </div>

        

        
      </div><!-- for_class-method -->

    
      <div id="method-c-for_id" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            for_id(id) &rarr; selector
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Creates a new selector for the given id.</p>
          

          
          <div class="method-source-code" id="for_id-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 225</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">for_id</span>(<span class="ruby-identifier">id</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>([<span class="ruby-node">&quot;#?&quot;</span>, <span class="ruby-identifier">id</span>])
<span class="ruby-keyword">end</span></pre>
          </div><!-- for_id-source -->
          
        </div>

        

        
      </div><!-- for_id-method -->

    
      <div id="method-c-new" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            new(string, [values ...]) &rarr; selector
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Creates a new selector from a CSS 2 selector expression.</p>

<p>The first argument is the selector expression. All other arguments are used
for value substitution.</p>

<p>Throws InvalidSelectorError is the selector expression is invalid.</p>
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 241</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">selector</span>, *<span class="ruby-identifier">values</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;CSS expression cannot be empty&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">selector</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-ivar">@source</span> = <span class="ruby-string">&quot;&quot;</span>
  <span class="ruby-identifier">values</span> = <span class="ruby-identifier">values</span>[<span class="ruby-value">0</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">values</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)

  <span class="ruby-comment"># We need a copy to determine if we failed to parse, and also</span>
  <span class="ruby-comment"># preserve the original pass by-ref statement.</span>
  <span class="ruby-identifier">statement</span> = <span class="ruby-identifier">selector</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">dup</span>

  <span class="ruby-comment"># Create a simple selector, along with negation.</span>
  <span class="ruby-identifier">simple_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">&quot;@#{name}&quot;</span>, <span class="ruby-identifier">value</span>) }

  <span class="ruby-ivar">@alternates</span> = []
  <span class="ruby-ivar">@depends</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-comment"># Alternative selector.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\s*,\s*/</span>, <span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-identifier">second</span> = <span class="ruby-constant">Selector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
    <span class="ruby-ivar">@alternates</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>
    <span class="ruby-comment"># If there are alternate selectors, we group them in the top selector.</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">alternates</span> = <span class="ruby-identifier">second</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value">:@alternates</span>)
      <span class="ruby-identifier">second</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value">:@alternates</span>, [])
      <span class="ruby-ivar">@alternates</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">alternates</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; , &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment"># Sibling selector: create a dependency into second selector that will</span>
  <span class="ruby-comment"># match element immediately following this one.</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\s*\+\s*/</span>, <span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-identifier">second</span> = <span class="ruby-identifier">next_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
    <span class="ruby-ivar">@depends</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">element</span> = <span class="ruby-identifier">next_element</span>(<span class="ruby-identifier">element</span>)
        <span class="ruby-identifier">second</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; + &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment"># Adjacent selector: create a dependency into second selector that will</span>
  <span class="ruby-comment"># match all elements following this one.</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\s*~\s*/</span>, <span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-identifier">second</span> = <span class="ruby-identifier">next_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
    <span class="ruby-ivar">@depends</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">matches</span> = []
      <span class="ruby-keyword">while</span> <span class="ruby-identifier">element</span> = <span class="ruby-identifier">next_element</span>(<span class="ruby-identifier">element</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">second</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span>)
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">first</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subset</span>.<span class="ruby-identifier">empty?</span>
            <span class="ruby-identifier">matches</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">first</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">else</span>
            <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">subset</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">matches</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; ~ &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment"># Child selector: create a dependency into second selector that will</span>
  <span class="ruby-comment"># match a child element of this one.</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\s*&gt;\s*/</span>, <span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-identifier">second</span> = <span class="ruby-identifier">next_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
    <span class="ruby-ivar">@depends</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">matches</span> = []
      <span class="ruby-identifier">element</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">second</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">child</span>, <span class="ruby-identifier">first</span>)
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">first</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subset</span>.<span class="ruby-identifier">empty?</span>
            <span class="ruby-identifier">matches</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">first</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">else</span>
            <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">subset</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">matches</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; &gt; &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment"># Descendant selector: create a dependency into second selector that</span>
  <span class="ruby-comment"># will match all descendant elements of this one. Note,</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">%r^\s+\S+/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">statement</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">selector</span>
    <span class="ruby-identifier">second</span> = <span class="ruby-identifier">next_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
    <span class="ruby-ivar">@depends</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span>, <span class="ruby-identifier">first</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">matches</span> = []
      <span class="ruby-identifier">stack</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">reverse</span>
      <span class="ruby-keyword">while</span> <span class="ruby-identifier">node</span> = <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
        <span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">tag?</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">second</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">first</span>)
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">first</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subset</span>.<span class="ruby-identifier">empty?</span>
            <span class="ruby-identifier">matches</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">first</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">else</span>
            <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">subset</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">children</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">children</span>
          <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">children</span>.<span class="ruby-identifier">reverse</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">matches</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">second</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-comment"># The last selector is where we check that we parsed</span>
    <span class="ruby-comment"># all the parts.</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid selector: #{statement}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
    </section><!-- public-class-method-details -->
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-match" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            match(element, first?) &rarr; array or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Matches an element against the selector.</p>

<p>For a simple selector this method returns an array with the element if the
element matches, nil otherwise.</p>

<p>For a complex selector (sibling and descendant) this method returns an
array with all matching elements, nil if no match is found.</p>

<p>Use +first_only=true+ if you are only interested in the first element.</p>

<p>For example:</p>

<pre>if selector.match(element)
  puts &quot;Element is a login form&quot;
end</pre>
          

          
          <div class="method-source-code" id="match-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 365</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">match</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">first_only</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-comment"># Match element if no element name or element name same as element name</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">matched</span> = (<span class="ruby-operator">!</span><span class="ruby-ivar">@tag_name</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@tag_name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">name</span>)
    <span class="ruby-comment"># No match if one of the attribute matches failed</span>
    <span class="ruby-keyword">for</span> <span class="ruby-identifier">attr</span> <span class="ruby-keyword">in</span> <span class="ruby-ivar">@attributes</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">attr</span>[<span class="ruby-value">0</span>]] <span class="ruby-operator">!~</span> <span class="ruby-identifier">attr</span>[<span class="ruby-value">1</span>]
        <span class="ruby-identifier">matched</span> = <span class="ruby-keyword">false</span>
        <span class="ruby-keyword">break</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Pseudo class matches (nth-child, empty, etc).</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">matched</span>
    <span class="ruby-keyword">for</span> <span class="ruby-identifier">pseudo</span> <span class="ruby-keyword">in</span> <span class="ruby-ivar">@pseudo</span>
      <span class="ruby-keyword">unless</span> <span class="ruby-identifier">pseudo</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">element</span>)
        <span class="ruby-identifier">matched</span> = <span class="ruby-keyword">false</span>
        <span class="ruby-keyword">break</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Negation. Same rules as above, but we fail if a match is made.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">matched</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@negation</span>
    <span class="ruby-keyword">for</span> <span class="ruby-identifier">negation</span> <span class="ruby-keyword">in</span> <span class="ruby-ivar">@negation</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">negation</span>[<span class="ruby-value">:tag_name</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">name</span>
        <span class="ruby-identifier">matched</span> = <span class="ruby-keyword">false</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-keyword">for</span> <span class="ruby-identifier">attr</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">negation</span>[<span class="ruby-value">:attributes</span>]
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">attr</span>[<span class="ruby-value">0</span>]] <span class="ruby-operator">=~</span> <span class="ruby-identifier">attr</span>[<span class="ruby-value">1</span>]
            <span class="ruby-identifier">matched</span> = <span class="ruby-keyword">false</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">matched</span>
        <span class="ruby-keyword">for</span> <span class="ruby-identifier">pseudo</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">negation</span>[<span class="ruby-value">:pseudo</span>]
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">pseudo</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">element</span>)
            <span class="ruby-identifier">matched</span> = <span class="ruby-keyword">false</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">break</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">matched</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># If element matched but depends on another element (child,</span>
  <span class="ruby-comment"># sibling, etc), apply the dependent matches instead.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">matched</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@depends</span>
    <span class="ruby-identifier">matches</span> = <span class="ruby-ivar">@depends</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">first_only</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">matches</span> = <span class="ruby-identifier">matched</span> <span class="ruby-operator">?</span> [<span class="ruby-identifier">element</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># If this selector is part of the group, try all the alternative</span>
  <span class="ruby-comment"># selectors (unless first_only).</span>
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">first_only</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">matches</span>
    <span class="ruby-ivar">@alternates</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">alternate</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">matches</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">first_only</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">alternate</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">first_only</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">matches</span>
          <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">subset</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">matches</span> = <span class="ruby-identifier">subset</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">matches</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- match-source -->
          
        </div>

        

        
      </div><!-- match-method -->

    
      <div id="method-i-next_element" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">next_element</span><span
            class="method-args">(element, name = nil)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Return the next element after this one. Skips sibling text nodes.</p>

<p>With the <code>name</code> argument, returns the next element with that
name, skipping other sibling elements.</p>
          

          
          <div class="method-source-code" id="next_element-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 495</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">next_element</span>(<span class="ruby-identifier">element</span>, <span class="ruby-identifier">name</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">siblings</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">children</span>
    <span class="ruby-identifier">found</span> = <span class="ruby-keyword">false</span>
    <span class="ruby-identifier">siblings</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">element</span>)
        <span class="ruby-identifier">found</span> = <span class="ruby-keyword">true</span>
      <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">found</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">tag?</span>
        <span class="ruby-keyword">return</span> <span class="ruby-identifier">node</span> <span class="ruby-keyword">if</span> (<span class="ruby-identifier">name</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- next_element-source -->
          
        </div>

        

        
      </div><!-- next_element-method -->

    
      <div id="method-i-select" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            select(root) &rarr; array
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Selects and returns an array with all matching elements, beginning with one
node and traversing through all children depth-first. Returns an empty
array if no match is found.</p>

<p>The root node may be any element in the document, or the document itself.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-identifier">selector</span> = <span class="ruby-constant">HTML</span><span class="ruby-operator">::</span><span class="ruby-constant">Selector</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;input[type=text]&quot;</span>
<span class="ruby-identifier">matches</span> = <span class="ruby-identifier">selector</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">element</span>)
<span class="ruby-identifier">matches</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Found text field with name #{match.attributes['name']}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>
          

          
          <div class="method-source-code" id="select-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 455</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">select</span>(<span class="ruby-identifier">root</span>)
  <span class="ruby-identifier">matches</span> = []
  <span class="ruby-identifier">stack</span> = [<span class="ruby-identifier">root</span>]
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">node</span> = <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">match</span>(<span class="ruby-identifier">node</span>, <span class="ruby-keyword">false</span>)
      <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">matches</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">match</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">any?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">match</span>) }
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">children</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">children</span>
      <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">children</span>.<span class="ruby-identifier">reverse</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">matches</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- select-source -->
          
        </div>

        

        
      </div><!-- select-method -->

    
      <div id="method-i-select_first" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">select_first</span><span
            class="method-args">(root)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Similar to <a href="Selector.html#method-i-select">select</a> but returns
the first matching element. Returns <code>nil</code> if no element matches
the selector.</p>
          

          
          <div class="method-source-code" id="select_first-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 473</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">select_first</span>(<span class="ruby-identifier">root</span>)
  <span class="ruby-identifier">stack</span> = [<span class="ruby-identifier">root</span>]
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">node</span> = <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">subset</span> = <span class="ruby-identifier">match</span>(<span class="ruby-identifier">node</span>, <span class="ruby-keyword">true</span>)
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">first</span> <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">subset</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">children</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">children</span>
      <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">children</span>.<span class="ruby-identifier">reverse</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- select_first-source -->
          
        </div>

        

        
      </div><!-- select_first-method -->

    
    </section><!-- public-instance-method-details -->
  
     <section id="protected-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Protected Instance Methods</h3>

    
      <div id="method-i-attribute_match" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">attribute_match</span><span
            class="method-args">(equality, value)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Create a regular expression to match an attribute value based on the
equality operator (=, ^=, |=, etc).</p>
          

          
          <div class="method-source-code" id="attribute_match-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 689</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">attribute_match</span>(<span class="ruby-identifier">equality</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">regexp</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">equality</span>
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;=&quot;</span> <span class="ruby-keyword">then</span>
      <span class="ruby-comment"># Match the attribute value in full</span>
      <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{regexp}$&quot;</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;~=&quot;</span> <span class="ruby-keyword">then</span>
      <span class="ruby-comment"># Match a space-separated word within the attribute value</span>
      <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;(^|\s)#{regexp}($|\s)&quot;</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;^=&quot;</span>
      <span class="ruby-comment"># Match the beginning of the attribute value</span>
      <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{regexp}&quot;</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;$=&quot;</span>
      <span class="ruby-comment"># Match the end of the attribute value</span>
      <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{regexp}$&quot;</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;*=&quot;</span>
      <span class="ruby-comment"># Match substring of the attribute value</span>
      <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">regexp</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;|=&quot;</span> <span class="ruby-keyword">then</span>
      <span class="ruby-comment"># Match the first space-separated item of the attribute value</span>
      <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{regexp}($|\s)&quot;</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidSelectorError</span>, <span class="ruby-string">&quot;Invalid operation/value&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-comment"># Match all attributes values (existence check)</span>
      <span class="ruby-regexp">%r/</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- attribute_match-source -->
          
        </div>

        

        
      </div><!-- attribute_match-method -->

    
      <div id="method-i-next_selector" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">next_selector</span><span
            class="method-args">(statement, values)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Called to create a dependent selector (sibling, descendant, etc). Passes
the remainder of the statement that will be reduced to zero eventually, and
array of substitution values.</p>

<p>This method is called from four places, so it helps to put it here for
reuse. The only logic deals with the need to detect comma separators
(alternate) and apply them to the selector group of the top selector.</p>
          

          
          <div class="method-source-code" id="next_selector-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 802</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">next_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
  <span class="ruby-identifier">second</span> = <span class="ruby-constant">Selector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
  <span class="ruby-comment"># If there are alternate selectors, we group them in the top selector.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">alternates</span> = <span class="ruby-identifier">second</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value">:@alternates</span>)
    <span class="ruby-identifier">second</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value">:@alternates</span>, [])
    <span class="ruby-ivar">@alternates</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">alternates</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">second</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- next_selector-source -->
          
        </div>

        

        
      </div><!-- next_selector-method -->

    
      <div id="method-i-nth_child" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">nth_child</span><span
            class="method-args">(a, b, of_type, reverse)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns a lambda that can match an element against the nth-child pseudo
class, given the following arguments:</p>
<ul><li>
<p><code>a</code> -- Value of a part.</p>
</li><li>
<p><code>b</code> -- Value of b part.</p>
</li><li>
<p><code>of_type</code> -- True to test only elements of this type (of-type).</p>
</li><li>
<p><code>reverse</code> -- True to count in reverse order (last-).</p>
</li></ul>
          

          
          <div class="method-source-code" id="nth_child-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 724</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
  <span class="ruby-comment"># a = 0 means select at index b, if b = 0 nothing selected</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span> <span class="ruby-keyword">false</span> } <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
  <span class="ruby-comment"># a &lt; 0 and b &lt; 0 will never match against an index</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span> <span class="ruby-keyword">false</span> } <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">b</span> = <span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>   <span class="ruby-comment"># b &lt; 0 just picks last element from each group</span>
  <span class="ruby-identifier">b</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>  <span class="ruby-comment"># b == 0 is same as b == 1, otherwise zero based</span>
  <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
    <span class="ruby-comment"># Element must be inside parent element.</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">tag?</span>
    <span class="ruby-identifier">index</span> = <span class="ruby-value">0</span>
    <span class="ruby-comment"># Get siblings, reverse if counting from last.</span>
    <span class="ruby-identifier">siblings</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">children</span>
    <span class="ruby-identifier">siblings</span> = <span class="ruby-identifier">siblings</span>.<span class="ruby-identifier">reverse</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">reverse</span>
    <span class="ruby-comment"># Match element name if of-type, otherwise ignore name.</span>
    <span class="ruby-identifier">name</span> = <span class="ruby-identifier">of_type</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">found</span> = <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">for</span> <span class="ruby-identifier">child</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">siblings</span>
      <span class="ruby-comment"># Skip text nodes/comments.</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
          <span class="ruby-comment"># Shortcut when a == 0 no need to go past count</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">b</span>
            <span class="ruby-identifier">found</span> = <span class="ruby-identifier">child</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">element</span>)
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
          <span class="ruby-comment"># Only look for first b elements</span>
          <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">b</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">element</span>)
            <span class="ruby-identifier">found</span> = (<span class="ruby-identifier">index</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-comment"># Otherwise, break if child found and count ==  an+b</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">element</span>)
            <span class="ruby-identifier">found</span> = (<span class="ruby-identifier">index</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">b</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">found</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- nth_child-source -->
          
        </div>

        

        
      </div><!-- nth_child-method -->

    
      <div id="method-i-only_child" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">only_child</span><span
            class="method-args">(of_type)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Creates a only child lambda. Pass <code>of-type</code> to only look at
elements of its type.</p>
          

          
          <div class="method-source-code" id="only_child-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 774</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">only_child</span>(<span class="ruby-identifier">of_type</span>)
  <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
    <span class="ruby-comment"># Element must be inside parent element.</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">tag?</span>
    <span class="ruby-identifier">name</span> = <span class="ruby-identifier">of_type</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">other</span> = <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">for</span> <span class="ruby-identifier">child</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">children</span>
      <span class="ruby-comment"># Skip text nodes/comments.</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span>)
        <span class="ruby-keyword">unless</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">element</span>)
          <span class="ruby-identifier">other</span> = <span class="ruby-keyword">true</span>
          <span class="ruby-keyword">break</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-operator">!</span><span class="ruby-identifier">other</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- only_child-source -->
          
        </div>

        

        
      </div><!-- only_child-method -->

    
      <div id="method-i-simple_selector" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">simple_selector</span><span
            class="method-args">(statement, values, can_negate = true)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Creates a simple selector given the statement and array of substitution
values.</p>

<p>Returns a hash with the values <code>tag_name</code>,
<code>attributes</code>, <code>pseudo</code> (classes) and
<code>negation</code>.</p>

<p>Called the first time with <code>can_negate</code> true to allow negation.
Called a second time with false since negation cannot be negated.</p>
          

          
          <div class="method-source-code" id="simple_selector-source">
            <pre><span class="ruby-comment"># File /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/vendor/html-scanner/html/selector.rb, line 522</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">simple_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>, <span class="ruby-identifier">can_negate</span> = <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">tag_name</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">attributes</span> = []
  <span class="ruby-identifier">pseudo</span> = []
  <span class="ruby-identifier">negation</span> = []

  <span class="ruby-comment"># Element name. (Note that in negation, this can come at</span>
  <span class="ruby-comment"># any order, but for simplicity we allow if only first).</span>
  <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^(\*|[[:alpha:]][\w\-]*)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">match</span>.<span class="ruby-identifier">strip!</span>
    <span class="ruby-identifier">tag_name</span> = <span class="ruby-identifier">match</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">match</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;*&quot;</span>
    <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">match</span>
    <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Get identifier, class, attribute name, pseudo or negation.</span>
  <span class="ruby-keyword">while</span> <span class="ruby-keyword">true</span>
    <span class="ruby-comment"># Element identifier.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-node">%r^#(\?|[\w\-]+)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">id</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span>
        <span class="ruby-identifier">id</span> = <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;##{id}&quot;</span>
      <span class="ruby-identifier">id</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{Regexp.escape(id.to_s)}$&quot;</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)
      <span class="ruby-identifier">attributes</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-string">&quot;id&quot;</span>, <span class="ruby-identifier">id</span>]
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Class name.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\.([\w\-]+)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">class_name</span> = <span class="ruby-node">$1</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;.#{class_name}&quot;</span>
      <span class="ruby-identifier">class_name</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;(^|\s)#{Regexp.escape(class_name)}($|\s)&quot;</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">class_name</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)
      <span class="ruby-identifier">attributes</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-string">&quot;class&quot;</span>, <span class="ruby-identifier">class_name</span>]
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Attribute value.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|&quot;[^*]&quot;|[^\]]*)\s*\]/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">name</span>, <span class="ruby-identifier">equality</span>, <span class="ruby-identifier">value</span> = <span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>, <span class="ruby-node">$3</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span>
        <span class="ruby-identifier">value</span> = <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-comment"># Handle single and double quotes.</span>
        <span class="ruby-identifier">value</span>.<span class="ruby-identifier">strip!</span>
        <span class="ruby-keyword">if</span> (<span class="ruby-identifier">value</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">&quot;&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">''</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>[<span class="ruby-value">-1</span>]
          <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;[#{name}#{equality}'#{value}']&quot;</span>
      <span class="ruby-identifier">attributes</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">name</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">strip</span>, <span class="ruby-identifier">attribute_match</span>(<span class="ruby-identifier">equality</span>, <span class="ruby-identifier">value</span>)]
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Root element only.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:root/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">element</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">tag?</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;:root&quot;</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Nth-child including last and of-type.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:nth-(last-)?(child|of-type)\((odd|even|(\d+|\?)|(-?\d*|\?)?n([+\-]\d+|\?)?)\)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">reverse</span> = <span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;last-&quot;</span>
      <span class="ruby-identifier">of_type</span> = <span class="ruby-node">$2</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;of-type&quot;</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:nth-#{$1}#{$2}(&quot;</span>
      <span class="ruby-keyword">case</span> <span class="ruby-node">$3</span>
        <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;odd&quot;</span>
          <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-value">2</span>, <span class="ruby-value">1</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
          <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;odd)&quot;</span>
        <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;even&quot;</span>
          <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-value">2</span>, <span class="ruby-value">2</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
          <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;even)&quot;</span>
        <span class="ruby-keyword">when</span> <span class="ruby-regexp">%r^(\d+|\?)$/</span>  <span class="ruby-comment"># b only</span>
          <span class="ruby-identifier">b</span> = (<span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span> <span class="ruby-operator">:</span> <span class="ruby-node">$1</span>).<span class="ruby-identifier">to_i</span>
          <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
          <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{b})&quot;</span>
        <span class="ruby-keyword">when</span> <span class="ruby-regexp">%r^(-?\d*|\?)?n([+\-]\d+|\?)?$/</span>
          <span class="ruby-identifier">a</span> = (<span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span> <span class="ruby-operator">:</span>
               <span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;-&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-value">-1</span> <span class="ruby-operator">:</span> <span class="ruby-node">$1</span>).<span class="ruby-identifier">to_i</span>
          <span class="ruby-identifier">b</span> = (<span class="ruby-node">$2</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span> <span class="ruby-operator">:</span> <span class="ruby-node">$2</span>).<span class="ruby-identifier">to_i</span>
          <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
          <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">b</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-node">&quot;#{a}n+#{b})&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{a}n#{b})&quot;</span>)
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid nth-child #{match}&quot;</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-comment"># First/last child (of type).</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:(first|last)-(child|of-type)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">reverse</span> = <span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;last&quot;</span>
      <span class="ruby-identifier">of_type</span> = <span class="ruby-node">$2</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;of-type&quot;</span>
      <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">nth_child</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-identifier">of_type</span>, <span class="ruby-identifier">reverse</span>)
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:#{$1}-#{$2}&quot;</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-comment"># Only child (of type).</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:only-(child|of-type)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">of_type</span> = <span class="ruby-node">$1</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;of-type&quot;</span>
      <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">only_child</span>(<span class="ruby-identifier">of_type</span>)
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:only-#{$1}&quot;</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Empty: no child elements or meaningful content (whitespaces</span>
    <span class="ruby-comment"># are ignored).</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:empty/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">empty</span> = <span class="ruby-keyword">true</span>
        <span class="ruby-keyword">for</span> <span class="ruby-identifier">child</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">children</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">tag?</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">child</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">empty?</span>
            <span class="ruby-identifier">empty</span> = <span class="ruby-keyword">false</span>
            <span class="ruby-keyword">break</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">empty</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;:empty&quot;</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-comment"># Content: match the text content of the element, stripping</span>
    <span class="ruby-comment"># leading and trailing spaces.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:content\(\s*(\?|'[^']*'|&quot;[^&quot;]*&quot;|[^)]*)\s*\)/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">content</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">content</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;?&quot;</span>
        <span class="ruby-identifier">content</span> = <span class="ruby-identifier">values</span>.<span class="ruby-identifier">shift</span>
      <span class="ruby-keyword">elsif</span> (<span class="ruby-identifier">content</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">&quot;&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">content</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">''</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">content</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">content</span>[<span class="ruby-value">-1</span>]
        <span class="ruby-identifier">content</span> = <span class="ruby-identifier">content</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:content('#{content}')&quot;</span>
      <span class="ruby-identifier">content</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{Regexp.escape(content.to_s)}$&quot;</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">content</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)
      <span class="ruby-identifier">pseudo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">text</span> = <span class="ruby-string">&quot;&quot;</span>
        <span class="ruby-keyword">for</span> <span class="ruby-identifier">child</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">children</span>
          <span class="ruby-keyword">unless</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">tag?</span>
            <span class="ruby-identifier">text</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">content</span>
          <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">text</span>.<span class="ruby-identifier">strip</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">content</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-string">&quot;&quot;</span> <span class="ruby-comment"># Remove</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Negation. Create another simple selector to handle it.</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^:not\(\s*/</span>, <span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Double negatives are not missing feature&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">can_negate</span>
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;:not(&quot;</span>
      <span class="ruby-identifier">negation</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">simple_selector</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>, <span class="ruby-keyword">false</span>)
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Negation not closed&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r^\s*\)/</span>, <span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-ivar">@source</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;)&quot;</span>
      <span class="ruby-keyword">next</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># No match: moving on.</span>
    <span class="ruby-keyword">break</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Return hash. The keys are mapped to instance variables.</span>
  {<span class="ruby-value">:tag_name=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">tag_name</span>, <span class="ruby-value">:attributes=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">attributes</span>, <span class="ruby-value">:pseudo=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">pseudo</span>, <span class="ruby-value">:negation=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">negation</span>}
<span class="ruby-keyword">end</span></pre>
          </div><!-- simple_selector-source -->
          
        </div>

        

        
      </div><!-- simple_selector-method -->

    
    </section><!-- protected-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

